package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.SetmealDish;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {
    /**
     * 根据菜品id查询对应套餐id
     *
     * @param dishIds
     * @return
     */
    List<Long> getSetmealIdByDishIds(List<Long> dishIds);

    /**
     * 批量保存套餐和菜品的关联关系
     *
     * @param setmealDishes
     */
    void insertBatch(List<SetmealDish> setmealDishes);


    /**
     * 分页查询
     *
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 根据套餐id删除套餐和菜品的关联数据
     * @param setmealId
     */


    /**
     * 根据套餐id查询套餐和菜品的关联数据
     *
     * @param id
     * @return
     */
    @Select("select * from setmeal_dish where setmeal_id = #{id} ")
    List<SetmealDish> getBySetmealId(Long id);

    //删除套餐和菜品的关联数据
    @Delete("delete from setmeal_dish where setmeal_id=#{setmealId} ")
    void deleteBySetmealId(Long ids);

    /**
     * 根据套餐id查询套餐信息
     *
     * @param id
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemById(Long id);

    List<Long> getSetmealIdsByDishIds(List<Long> dishIds);
}
